package com.uenpay.im.invokeitems.login;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.utils.Utils;
import com.qyx.android.utilities.DateUtils;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * 忘记密码
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class ForgetPwdInvokeItem extends HttpInvokeItem {

	public class ForgetPwdInvokeItemResult {
		public int status;
		public String msg;
	}

	public ForgetPwdInvokeItemResult getOutput() {
		return (ForgetPwdInvokeItemResult) GetResultObject();
	}

	public ForgetPwdInvokeItem(String mobile_phone, String phone_validate_code,
			String new_password) {
		String time = DateUtils.getCurrentSeconds() + "";
		String sign = Utils.md5(Utils.md5(mobile_phone + "_" + time));
		String url = APIConfiguration.getBaseUrl() + "Cust/Init/updatePwd?";
		HashMap<String, String> mRequestParams = new HashMap<String, String>();
		mRequestParams.put("username", mobile_phone);
		mRequestParams.put("password", new_password);
		mRequestParams.put("vercode", phone_validate_code);
		mRequestParams.put("time", time);
		mRequestParams.put("sign", sign);
		SetRequestParams(mRequestParams);
		SetMethod("POST");
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		ForgetPwdInvokeItemResult result = new ForgetPwdInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}
}
